package com.yanqu.road.server.cmd.chefduel.process3;

import com.yanqu.road.entity.activity.chefduel.process2.ChefDuelUpUser;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.chefduel.ChefDuelProto;
import com.yanqu.road.server.cmd.CrossCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.logic.MessageHelper;
import com.yanqu.road.server.manager.chefduel.CrossChefDuel3;
import com.yanqu.road.server.manager.chefduel.CrossChefDuelMgr;
import com.yanqu.road.server.protocol.Protocol;
import com.yanqu.road.utils.YanQuMessageUtils;

@Cmd(code = Protocol.C_CHEF_DUEL3_DATA_SYNC, desc = "玩家信息同步")
public class CrossChefDuel3SelfDataSyncCmd extends CrossCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        ChefDuelProto.ChefDuel3SelfDataSyncMsg syncMsg = ChefDuelProto.ChefDuel3SelfDataSyncMsg.parseFrom(packet.getBytes());
        int activityId = syncMsg.getActivityId();
        CrossChefDuel3 chefDuel3 = CrossChefDuelMgr.getCrossChefDuel3IfNull(activityId);
        if(chefDuel3 != null){
            ChefDuelProto.ChefDuel3SelfDataSyncMsg.Builder clientMsg = syncMsg.toBuilder();
            ChefDuelUpUser chefDuelUpUser = chefDuel3.getChefDuelMap().get(packet.getPlayerId());
            if(chefDuelUpUser != null){
                clientMsg.setSupportRewardGet(chefDuelUpUser.getCampRewardGet() == 1);
            }
            MessageHelper.sendPacket(serverId, packet.getPlayerId(), YanQuMessageUtils.buildMessage(Protocol.U_CHEF_DUEL3_DATA_SYNC, clientMsg));
        }
    }

    @Override
    public void sendData() {

    }
}
